<?php

include_once('class.pog_base.php');
class news extends POG_Base
{
	public $idetu = '';

	public $nometu;

	public $preetu;

	public $teletu;

	public $maileetu;

	public $pog_attribute_type = array(
		"idetu" => array('db_attributes' => array("NUMERIC", "INT")),
		"nometu" => array('db_attributes' => array("TEXT", "VARCHAR", "50")),
		"preetu" => array('db_attributes' => array("TEXT", "VARCHAR", "50")),
		"teletu" => array('db_attributes' => array("TEXT", "VARCHAR", "10")),
		"maileetu" => array('db_attributes' => array("TEXT", "VARCHAR", "50")),
		);
	public $pog_query;

	public function __get($attribute)
	{
		if (isset($this->{"_".$attribute}))
		{
			return $this->{"_".$attribute};
		}
		else
		{
			return false;
		}
	}

	function news($nometu='', $preetu='', $teletu='', $maileetu='')
	{
		$this->nometu = $nometu;
		$this->preetu = $preetu;
		$this->teletu = $teletu;
		$this->maileetu = $maileetu;
	}

	function Get($idetu)
	{
		$connexion = Database::Connect();
		$this->pog_query = "select * from `etudiant` where `idetu`='".intval($idetu)."' LIMIT 1";
		$cursor = Database::Reader($this->pog_query, $connexion);
		while ($row = Database::Read($cursor))
		{
			$this->idetu = $row['idetu'];
			$this->nometu = $this->Unescape($row['nometu']);
			$this->preetu = $this->Unescape($row['preetu']);
			$this->teletu = $this->Unescape($row['teletu']);
			$this->maileetu = $this->Unescape($row['maileetu']);
		}
		return $this;
	}

	function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
	{
		$connexion = Database::Connect();
		$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
		$this->pog_query = "select * from `etudiant` ";
		$newsList = Array();
		if (sizeof($fcv_array) > 0)
		{
			$this->pog_query .= " where ";
			for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
			{
				if (sizeof($fcv_array[$i]) == 1)
				{
					$this->pog_query .= " ".$fcv_array[$i][0]." ";
					continue;
				}
				else
				{
					if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
					{
						$this->pog_query .= " AND ";
					}
					if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
					{
						if ($GLOBALS['configuration']['db_encoding'] == 1)
						{
							$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
							$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
						}
						else
						{
							$value =  POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
							$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
						}
					}
					else
					{
						$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
						$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
					}
				}
			}
		}
		if ($sortBy != '')
		{
			if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
			{
				if ($GLOBALS['configuration']['db_encoding'] == 1)
				{
					$sortBy = "BASE64_DECODE($sortBy) ";
				}
				else
				{
					$sortBy = "$sortBy ";
				}
			}
			else
			{
				$sortBy = "$sortBy ";
			}
		}
		else
		{
			$sortBy = "idetu";
		}
		$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
		$thisObjectName = get_class($this);
		$cursor = Database::Reader($this->pog_query, $connexion);
		while ($row = Database::Read($cursor))
		{
			$etudiant = new $thisObjectName();
			$etudiant->idetu = $row['idetu'];
			$etudiant->nometu = $this->Unescape($row['nometu']);
			$etudiant->preetu = $this->Unescape($row['preetu']);
			$etudiant->teletu = $this->Unescape($row['teletu']);
			$etudiant->maileetu = $this->Unescape($row['maileetu']);
			$newsList[] = $etudiant;
		}
		return $newsList;
	}

	function Save()
	{
		$connexion = Database::Connect();
		$this->pog_query = "select `idetu` from `etudiant` where `idetu`='".$this->idetu."' LIMIT 1";
		$rows = Database::Query($this->pog_query, $connexion);
		if ($rows > 0)
		{
			$this->pog_query = "update `etudiant` set 
			`nometu`='".$this->Escape($this->nometu)."', 
			`preetu`='".$this->Escape($this->preetu)."', 
			`teletu`='".$this->Escape($this->teletu)."', 
                        `maileetut`='".$this->Escape($this->maileetut)."' where `idetu`='".$this->idetu."'";
		}
		else
		{
			$this->pog_query = "insert into `etudiant` (`nometu`, `preetu`, `teletu`, `maileetu` ) values (
			'".$this->Escape($this->nometu)."', 
			'".$this->Escape($this->preetu)."', 
			'".$this->Escape($this->teletu)."', 
			'".$this->Escape($this->maileetu)."' )";
		}
		$insertId = Database::InsertOrUpdate($this->pog_query, $connexion);
		if ($this->idetu == "")
		{
			$this->idetu = $insertId;
		}
		return $this->idetu;
	}

	function SaveNew()
	{
		$this->idetu = '';
		return $this->Save();
	}

	function Delete()
	{
		$connexion = Database::Connect();
		$this->pog_query = "delete from `etudiant` where `idetu`='".$this->idetu."'";
		return Database::NonQuery($this->pog_query, $connexion);
	}

	function DeleteList($fcv_array)
	{
		if (sizeof($fcv_array) > 0)
		{
			$connexion = Database::Connect();
			$pog_query = "delete from `etudiant` where ";
			for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
			{
				if (sizeof($fcv_array[$i]) == 1)
				{
					$pog_query .= " ".$fcv_array[$i][0]." ";
					continue;
				}
				else
				{
					if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
					{
						$pog_query .= " AND ";
					}
					if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
					{
						$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
					}
					else
					{
						$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
					}
				}
			}
			return Database::NonQuery($pog_query, $connexion);
		}
	}
        
        function listeEleve()
        {
            $connexion = Database::Connect();
            $this->pog_query = "select * from etudiant";
            $rows = Database::Query($this->pog_query, $connexion);
            
            
        }
}

?>